package com.dk.common.dbaccess.interceptor;

import org.hibernate.resource.jdbc.spi.StatementInspector;

public class SoftDeleteInterceptor implements StatementInspector {

    @Override
    public String inspect(String sql) {
        if (shouldIntercept(sql)) {
            /*// 获取 Connection 对象
            EntityManager entityManager = SpringUtil.getBean(EntityManager.class);
            Session session = (Session) entityManager.getDelegate();
            Connection connection = session.doReturningWork(conn -> conn);
            return SoftDeleteSqlParser.addSoftDeleteCondition(sql,connection);*/
        }
        return sql;
    }

    private boolean shouldIntercept(String sql) {
        if (sql == null) return false;

        String upperSql = sql.toUpperCase().trim();
        return upperSql.startsWith("DELETE");  // 避免重复添加

    }


}